/**
  ******************************************************************************
  * @file   :   main.c
  * @version:
  * @author :
  * @brief  :
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; Copyright(c) . BLUEX Microelectronics.
  * All rights reserved.</center></h2>
  *
  *
  ******************************************************************************
  */

/* includes ------------------------------------------------------------------*/

#include "bx_kernel.h"
#include "user_app.h"

#include "bx_service_tim.h"
#include "bx_service_gpio.h"
/* private define ------------------------------------------------------------*/
#define    LED2     2
#define    LED1     3
/* private typedef -----------------------------------------------------------*/

/* private variables ---------------------------------------------------------*/

/* exported variables --------------------------------------------------------*/


/*============================= private function =============================*/

/*========================= end of private function ==========================*/


/*============================= exported function ============================*/
/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_init( void )
{
	bxs_tim_register();
	bxs_gpio_register();
}

/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
void user_app( void )
{
   s32 id0 = bxs_tim0_id();
   s32 id1 = bxs_tim1_id();
   s32 id_gpio = bxs_gpio_a_id();

   bx_call(id0,BXM_OPEN,0,0);
   bx_call(id1,BXM_OPEN,0,0);

   bx_call(id_gpio,BXM_OPEN,0,0);

   bx_call(id0,BXM_START,1000000,0);
   bx_call(id1,BXM_START,500000,0);

   bx_set(id_gpio,BXP_MODE,LED2,BX_GPIO_MODE_OUTPUT);
   bx_set(id_gpio,BXP_MODE,LED1,BX_GPIO_MODE_OUTPUT);

   bx_subscibe(id0, BXM_TIM0_INTR, 0, 0);
   bx_subscibe(id1, BXM_TIM1_INTR, 0, 0);

}
/** ---------------------------------------------------------------------------
 * @brief   :
 * @note    :
 * @param   :
 * @retval  :
-----------------------------------------------------------------------------*/
bx_err_t user_msg_handle_func(s32 svc, u32 msg,u32 param0,u32 param1 )
{
    s32 id_gpio = bxs_gpio_a_id();
	
    if((bx_msg_source() != bxs_tim0_id())&&(bx_msg_source() != bxs_tim1_id()))
    {
		return 0;
	}
	switch(msg)
	{
		case BXM_TIM0_INTR:
			bx_call(id_gpio,BXM_TOGGLE,LED2,0);
			break;

		case BXM_TIM1_INTR:
			bx_call(id_gpio,BXM_TOGGLE,LED1,0);
			break;
	}
    return BX_OK;
}
/*========================= end of exported function =========================*/


/*============================= import function ==============================*/

/*=========================== end of import function =========================*/


/*============================ interrupt function ============================*/

/*========================= end of interrupt function ========================*/

  
/******************** (C) COPYRIGHT BLUEX **********************END OF FILE****/



